package cn.mw.cmdb.viewProcessor;

import cn.mw.cmdb.entity.ModelInfo;
import cn.mw.cmdb.param.ModelPropertyParam;
import cn.mw.cmdb.processor.ModelViewTypeContext;
import cn.mw.cmdb.processor.ModelViewTypeProccessor;
import cn.mw.cmdb.service.impl.CmdbServiceManage;
import cn.mw.cmdb.service.impl.ModelGroupServiceImpl;
import cn.mw.cmdb.service.impl.ModelPropertyServiceImpl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static cn.mw.cmdb.viewProcessor.ModelViewCabinetProcess.getCabinetPropertyIds;
import static cn.mw.cmdb.viewProcessor.ModelViewRoomProcess.getRoomPropertyIds;
import static cn.mw.cmdb.viewProcessor.ModelViewUNumProcess.getUNumTypePropertyIds;

public class ModelViewDefaultProcess implements ModelViewTypeProccessor {

    @Override
    public Object genModelViewProperty(ModelViewTypeContext context) throws Exception {
        if (context != null && context.getParam() != null && (context.getParam() instanceof ModelInfo)) {
            ModelInfo param = (ModelInfo) context.getParam();
            CmdbServiceManage cmdbServiceManage = context.getCmdbServiceManage();

            ModelPropertyServiceImpl service = (ModelPropertyServiceImpl) cmdbServiceManage.getModelService(ModelPropertyServiceImpl.ID);

            //清除其他视图对应的字段
            ModelPropertyParam propertyParam = editorModelPropertyField(param);
            service.doRemove(propertyParam);
        }
        return null;
    }

    /**
     * 清除U位管理视图对应的字段
     */
    public static ModelPropertyParam editorModelPropertyField(ModelInfo param) {
        ModelPropertyParam propertyParam = new ModelPropertyParam();
        Set<String> ids = new HashSet<>();
        getRoomPropertyIds(ids);
        getUNumTypePropertyIds(ids);
        getCabinetPropertyIds(ids);
        propertyParam.setIds(new ArrayList<>(ids));
        propertyParam.setModelId(param.getId());
        return propertyParam;
    }

    @Override
    public Object addInstanceHandle(ModelViewTypeContext context) throws Exception {
        return null;
    }

    @Override
    public Object updInstanceHandle(ModelViewTypeContext context) throws Exception {
        return null;
    }


}
